package part1.miniTomcat;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author 大忽悠
 * @create 2022/9/1 9:50
 */
public class Request {
    private static final Integer BUFFER_SIZE=2048;
    private InputStream in;
    /**
     * 请求URI
     */
    private String uri;

    public Request(InputStream in) {
       this.in=in;
    }

    public void parse() {
        int count;
        byte[] buffer = new byte[BUFFER_SIZE];

        try {
            count = in.read(buffer);
            //获取到HTTP请求报文
            String requestMessage = new String(buffer, 0, count);
            parseUri(requestMessage);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void parseUri(String requestMessage) {
        String[] split = requestMessage.split("\r\n");
        String[] firstLine = split[0].split(" ");
        uri=firstLine[1];
    }

    public String getUri() {
     return uri;
    }
}
